package org.jing.core.lang.data.json;

import org.jing.core.lang.JingException;

/**
 * Description: Json对象类型 <br>
 *
 * @author bks <br>
 * @since 2024-07-22 <br>
 */
public enum TokenType {

    BEGIN_OBJECT(1),

    END_OBJECT(2),

    BEGIN_ARRAY(4),

    END_ARRAY(8),

    NULL(16),

    NUMBER(32),

    STRING(64),

    BOOLEAN(128),

    /**
     * Description: 冒号'<b>:</b>' <br>
     */
    SEP_COLON(256),

    /**
     * Description: 逗号'<b>,</b>' <br>
     */
    SEP_COMMA(512),

    END_DOCUMENT(1024);

    TokenType(int code) {
        this.code = code;
    }

    private final int code;

    public int getTokenCode() {
        return code;
    }

    public void checkExpectToken(int expectToken) {
        if ((code & expectToken) == 0) {
            throw new JingException("parse error, invalid token: {}", this);
        }
    }
}
